package org.kfish.framework.log;

import java.io.InputStream;

import org.kfish.framework.ConfigConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;

public class Log {

	public static enum LogType {
		SIMPLE, DETAIL
	};

	/**
	 * 初始化日志配置
	 * 
	 * @param in
	 */
	public static void init(InputStream in) {
		if (in != null) {
			LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
			JoranConfigurator configurator = new JoranConfigurator();
			configurator.setContext(lc);
			lc.reset();
			try {
				configurator.doConfigure(in);
			} catch (JoranException e) {
				e.printStackTrace();
			}
		}

	}

	public static Logger getLogger(LogType logType) {

		Logger logger;

		switch (logType) {
		case SIMPLE:
			logger = LoggerFactory.getLogger(ConfigConstant.LOG_SIMPLE);
			break;
		case DETAIL:
			logger = LoggerFactory.getLogger(ConfigConstant.LOG_DETAIL);
			break;
		default:
			logger = LoggerFactory.getLogger(ConfigConstant.LOG_DETAIL);
			break;
		}
		return logger;
	}

}
